# MODELS

# Fit ATE models ---------------------------------------------------------------

# Fit models for confidence in attribution
at_ln <- fit_bulk(iv, "confidence", "linear")
at_lg <- fit_bulk(iv, "confidence", "logistic")
at_or <- fit_bulk(iv, "confidence", "ordinal")
at_mt <- fit_bulk(iv, "confidence", "multinomial")
at_ln$DropNA <- lapply(var_NA, fit_models, "confidence", "linear")

# Fit models for support for highest retribution 
rt_ln <- fit_bulk(iv, "support", "linear")
rt_lg <- fit_bulk(iv, "support", "logistic")
rt_or <- fit_bulk(iv, "support", "ordinal")
rt_mt <- fit_bulk(iv, "support", "multinomial")
rt_ln$DropNA <- lapply(var_NA, fit_models, "support", "linear")

# Fit logistic and OLS models for each strategy
st_do_nothing <- fit_strategy(var_ind, "do_nothing")
st_do_condemn <- fit_strategy(var_ind, "do_condemn")
st_do_sanction <- fit_strategy(var_ind, "do_sanctions")
st_do_espionage <- fit_strategy(var_ind, "do_cyberespionage")
st_do_airstrike <- fit_strategy(var_ind, "do_airstrikes")

if (experiment == "1") {
  st_do_cyberattack <- fit_strategy(var_ind, "do_cyberattack")
} else if (experiment == "2") {
  st_do_duma <- fit_strategy(var_ind, "do_cyberduma")
  st_do_kremlin <- fit_strategy(var_ind, "do_cyberkremlin")
} else if (experiment == "3") {
  st_do_powergrid <- fit_strategy(var_ind, "do_powergrid")
  st_do_cyberattack <- fit_strategy(var_ind, "do_cyberattack")
}

if (experiment == "3") {
  st_un_nothing <- fit_strategy(var_ind, "un_nothing")
  st_un_condemn <- fit_strategy(var_ind, "un_condemn")
  st_un_sanction <- fit_strategy(var_ind, "un_sanction")
  st_un_force <- fit_strategy(var_ind, "un_force")
}

# Fit models for subgroups with interaction effects (CATE) ---------------------
subgroups <- list("Party" = "party", 
                  "CI" = "ci_high",
                  "MI" = "mi_high",
                  "ISO" = "iso_high")

subgroups <- if (experiment == "1") {
  append(subgroups, list("China"="china_imputed", "EU"="eu_imputed"))
} else if (experiment == "2") {
  append(subgroups, list("Russia"="russia_imputed"))
} else if (experiment == "3") {
  append(subgroups, list("Iran"="iran_imputed", "Israel"="israel_imputed", 
                         "EU"="eu_imputed"))
}

at_cate <- lapply(subgroups, \(x) fit_cate("confidence", x))
rt_cate <- lapply(subgroups, \(x) fit_cate("support", x))